<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <title>Allocation Information Management in Shared Area</title>
    <script type="text/javascript">
		var path = "<%=basePath%>";
	</script>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>beshs/css/content.css" />
	<script type="text/javascript" src="<%=basePath%>resources/jquery/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/datepicker/datepicker.js"></script>
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
	<!-- 用户访问菜单路径 -->
	<jsp:include page="/resources/usertrace/common-uservisit-reference.jsp" />
  </head>
  <script type="text/javascript">
  	function formVerify() {
  		var verify = true;
  		//所属项目
  		var projectID = $("select[name='shareAreaResult.projectID']").val();
  		if(projectID == "") {
  			$("select[name='shareAreaResult.projectID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("select[name='shareAreaResult.projectID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		//所属小区
  		var communityID = $("select[name='shareAreaResult.communityID']").val();
  		if(communityID == "") {
  			$("select[name='shareAreaResult.communityID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("select[name='shareAreaResult.communityID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		//所属分摊域
  		var shareAreaID = $("select[name='shareAreaResult.shareAreaID']").val();
  		if(shareAreaID == "") {
  			$("select[name='shareAreaResult.shareAreaID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("select[name='shareAreaResult.shareAreaID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		//分摊名称
  		var shareName = $("input[name='shareName']").val();
  		if($.trim(shareName) == "") {
  			$("input[name='shareName']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("input[name='shareName']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		//开始日期
  		var startDate = $("input[name='startDate']").val();
  		if($.trim(startDate) == "") {
  			$("input[name='startDate']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("input[name='startDate']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		//结束日期
  		var endDate = $("input[name='endDate']").val();
  		if($.trim(endDate) == "") {
  			$("input[name='endDate']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("input[name='endDate']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		//分摊方法
  		var shareType = $("select[name='shareAreaResult.shareType']").val();
  		if(shareType == "") {
  			$("select[name='shareAreaResult.shareType']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("select[name='shareAreaResult.shareType']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		return verify;
  	}
  
  	function submitForm() {
  		var areaResultUID = "<s:property value='areaResultUID' />";
  		//表单校验
  		var verify = formVerify();
  		if(!verify) return;
  		//-------------------表单信息
  		//所属项目
  		var projectID = $("select[name='shareAreaResult.projectID']").val();
  		//所属小区
  		var communityID = $("select[name='shareAreaResult.communityID']").val();
  		//所属分摊域
  		var shareAreaID = $("select[name='shareAreaResult.shareAreaID']").val();
  		//分摊名称
  		var shareName = $("input[name='shareName']").val();
  		//开始日期
  		var startDate = $("input[name='startDate']").val();
  		//结束日期
  		var endDate = $("input[name='endDate']").val();
  		//分摊方法
  		var shareType = $("select[name='shareAreaResult.shareType']").val();
  		//备注
  		var remark = $("textarea[name='remark']").val();
  		$.getJSON(path+"beshs/shareAreaResultActionJson!saveOrUpdateAreaResult.do?date="+new Date(), {
  			"shareAreaResult.id": areaResultUID,
  			"shareAreaResult.projectID": projectID,
  			"shareAreaResult.communityID": communityID,
  			"shareAreaResult.shareAreaID": shareAreaID,
  			"shareAreaResult.shareName": shareName,
  			"shareAreaResult.startDate": startDate,
  			"shareAreaResult.endDate": endDate,
  			"shareAreaResult.shareType": shareType,
  			"shareAreaResult.remark": remark
  		}, function(data){
  			if(data.success) {
  				Dialog.alert("Successful Operation！", function() {
  					var index = parent.layer.getFrameIndex(window.name)
					parent.window.frames["c_content_content"].location = path + "beshs/shareAreaResultAction!queryAreaResultPage.do?date"+new Date();
  					parent.layer.close(index);
  				});
  			} else {
  				Dialog.alert(data.msg);
  			}
  		});
  	}
  	
  	$(function(){
  		$("input[name='submit']").click(function(){
  			submitForm();
  		});
  	});
  </script>
  <body>
    <div class="content_all">
  		<!--导航条-->
  		<div class="insertinfo_table">
      		<form action="#"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        		<tr>
          			<th>Project：</th>
          			<td><s:select name="shareAreaResult.projectID" list="projectList" listKey="id" listValue="projectName" headerKey="" headerValue="Please select" cssClass="s_sel"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span></td>
            		<th>District：</th>
          			<td>
          				<script type="text/javascript">
          					function reloadCommunitys(projectUID, communityUID) {
          						$("select[name='shareAreaResult.communityID']").children("option").slice(1).remove();
	      						if(projectUID!=null && projectUID!="") {
	      							$.getJSON(path+"beshs/communityActionJson!queryCommunitysByBelongs.do?date="+new Date(), {
	      								projectUID: projectUID
	      							}, function(data){
	      								for(var index=0; index<data.length; index++) {
	      									if(communityUID!=null && communityUID!="" && communityUID==data[index].id) {
		        								$("select[name='shareAreaResult.communityID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].communityName+"</option>");
		        							} else {
		        								$("select[name='shareAreaResult.communityID']").append("<option value='"+data[index].id+"'>"+data[index].communityName+"</option>");
		        							}
	      								}
	      							});
	      						}
          					}
          					
          					$(function() {
	      						$("select[name='shareAreaResult.projectID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='shareAreaResult.communityID']").val();
			        				reloadCommunitys(projectUID, communityUID);
			        			});
	      					});
          				</script>
          				<s:select name="shareAreaResult.communityID" list="communityList" listKey="id" listValue="communityName" headerKey="" headerValue="Please select" cssClass="s_sel"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span></td>
        		</tr>
        		<tr>
          			<th>Shared Area：</th>
          			<td>
          				<script type="text/javascript">
	          				function reloadShareAreas(projectUID, communityUID, shareAreaUID) {
	      						$("select[name='shareAreaResult.shareAreaID']").children("option").slice(1).remove();
	      						if((projectUID!=null && projectUID!="") 
          								|| (communityUID!=null && communityUID!="")) {
		        					$.getJSON(path+"beshs/shareAreaActionJson!queryShareAreasByBelongings.do?date="+new Date(), {
		        						projectUID: projectUID,
		        						communityUID: communityUID
		        					}, function(data) {
		        						for(var index=0; index<data.length; index++) {
		        							if(shareAreaUID!=null && shareAreaUID!="" && shareAreaUID==data[index].id) {
		        								$("select[name='shareAreaResult.shareAreaID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].areaName+"</option>");
		        							} else {
		        								$("select[name='shareAreaResult.shareAreaID']").append("<option value='"+data[index].id+"'>"+data[index].areaName+"</option>");
		        							}
		        						}
		        						window.setTimeout(function() {
		        							reloadShareCycleDate();
		        						}, 300);
		        					});
		        				} 
	      					}
	      				
	          				$(function(){
	      						$("select[name='shareAreaResult.projectID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='shareAreaResult.communityID']").val();
			        				var shareAreaUID = $("select[name='shareAreaResult.shareAreaID']").val();
			        				reloadShareAreas(projectUID, communityUID, shareAreaUID);
			        			});
	      						
	      						$("select[name='shareAreaResult.communityID']").change(function(){
									var communityUID = $(this).val();
	      							var projectUID = $("select[name='shareAreaResult.projectID']").val();
	      							var shareAreaUID = $("select[name='shareAreaResult.shareAreaID']").val();
	      							reloadShareAreas(projectUID, communityUID, shareAreaUID);
	      						});
	      					});
          				</script>
          				<s:select name="shareAreaResult.shareAreaID" list="shareAreaList" listKey="id" listValue="areaName" headerKey="" headerValue="Please select" cssClass="s_sel"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span></td>
            		<th>Allocation Name：</th>
          			<td><input name="shareName" type="text" class="s_input" value="<s:property value='shareAreaResult.shareName' />" />
            			&nbsp;<span style="color:#FF0000;">*</span></td>
        		</tr>
        		<tr>
        			<th>Allocation Period Start Date</th>
        			<td>
        				<script type="text/javascript">
	        				function reloadShareCycleDate() {
	    						//清空分摊周期的开始日期和结束日期
								$("input[name='startDate']").val("");
								$("input[name='endDate']").val("");
								//根据所属分摊域的起止日期重新设置分摊域分摊的起止日期
								var shareAreaUID = $("select[name='shareAreaResult.shareAreaID']").val();
								if(shareAreaUID != "") {
									$.getJSON(path+"beshs/shareAreaActionJson!queryShareAreaEntityByUID.do?date="+new Date(), {
										shareAreaUID: shareAreaUID
									}, function(data) {
										var startDate = data.startDate;
										if(startDate!=null && $.trim(startDate)!="" && $.trim(startDate)!="null") {
											startDate = startDate.substring(0, startDate.lastIndexOf("T"));
											$("input[name='startDate']").val(startDate);
										}
										var endDate = data.endDate;
										if(endDate!=null && $.trim(endDate)!="" && $.trim(endDate)!="null") {
											endDate = endDate.substring(0, endDate.lastIndexOf("T"));
											$("input[name='endDate']").val(endDate);
										}
									});
								}
	    					}	
	        				
	        				$(function() {
	        					$("select[name='shareAreaResult.shareAreaID']").change(function() {
	        						reloadShareCycleDate();
	        					});
	        				});
        				</script>
        				<input id="areaResult_startDate" name="startDate" class="Wdate" value="<s:date name='shareAreaResult.startDate' format='yyyy-MM-dd' nice='false' />" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})" />
        				
<%--         				<input name="startDate" id="areaResult_startDate" type="text" class="s_input" value="<s:date name='shareAreaResult.startDate' format='yyyy-MM-dd' nice='false' />" onclick="selectDate(this,'yyyy-MM-dd')" readonly/> --%>
<%--           				<img src="<%=basePath%>resources/datepicker/calendar.jpg" onclick="txtSelectDate('areaResult_startDate','yyyy-MM-dd')"/> --%>
        				&nbsp;<span style="color:#FF0000;">*</span></td>
        			<th>Allocation Period End Date</th>
        			<td>
        			<input id="areaResult_endDate" name="endDate" class="Wdate" value="<s:date name='shareAreaResult.endDate' format='yyyy-MM-dd' nice='false' />" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})" />
        				
<%--         				<input name="endDate" id="areaResult_endDate" type="text" class="s_input" value="<s:date name='shareAreaResult.endDate' format='yyyy-MM-dd' nice='false' />" onclick="selectDate(this,'yyyy-MM-dd')" readonly/> --%>
<%--           				<img src="<%=basePath%>resources/datepicker/calendar.jpg" onclick="txtSelectDate('areaResult_endDate','yyyy-MM-dd')"/> --%>
        				&nbsp;<span style="color:#FF0000;">*</span></td>
        		</tr>
        		<tr>
        			<th>Average Allocation Method</th>
        			<td>
        				<script type="text/javascript">
        					$(function() {
        						$("select[name='shareAreaResult.shareType']").change(function() {
        							var shareType = $("select[name='shareAreaResult.shareType']").val();
        							if(shareType == 2) {
        								$("input[name='startDate']").attr("disabled", "disabled");
        								$("input[name='startDate']").parent("td").find("img").attr("disabled", "disabled");
        								$("input[name='endDate']").attr("disabled", "disabled");
        								$("input[name='endDate']").parent("td").find("img").attr("disabled", "disabled");
        							} else {
        								$("input[name='startDate']").removeAttr("disabled");
        								$("input[name='startDate']").parent("td").find("img").removeAttr("disabled");
        								$("input[name='endDate']").removeAttr("disabled");
        								$("input[name='endDate']").parent("td").find("img").removeAttr("disabled");
        							}
        						});
        					});
        				</script>
        				<s:select name="shareAreaResult.shareType" list="#{'1':'Process Allocation', '2':'Charge Allocation'}" headerKey="" headerValue="Please select" cssClass="s_sel"></s:select>
        				&nbsp;<span style="color:#FF0000;">*</span></td>
        			<th></th>
        			<td></td>
        		</tr>
        		<tr>
        			<th>Remark：</th>
          			<td colspan="3">
          				<textarea name="remark" cols="45" rows="3"><s:property value='shareAreaResult.remark' /></textarea>
          			</td>
        		</tr>
        		<tr>
          			<td style="border:none;" colspan="4" align="center">
          				<input name="submit" type="button" value="Submit" class="s_btn" />
            			<input name="reset" type="reset" value="Reset" class="s_btn"/></td>
        		</tr>
      		</table></form>
  		</div>
	</div>
	<div class="clear"></div>
  </body>
</html>
